package com.example.quiz.service.impl;

import com.example.quiz.dao.WrongQuestionMapper;
import com.example.quiz.model.WrongQuestion;
import com.example.quiz.service.WrongQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class WrongQuestionServiceImpl implements WrongQuestionService {

    @Autowired
    private WrongQuestionMapper wrongQuestionMapper;

    @Override
    public List<WrongQuestion> getPagedQuestions(int page, int size, Long userId) {
        int offset = (page - 1) * size;
        return wrongQuestionMapper.selectPagedQuestions(offset, size, userId);
    }

    @Override
    public int getTotalCount(Long userId) {
        return wrongQuestionMapper.selectTotalCount(userId);
    }

    @Override
    @Transactional
    public int clearByUserId(Long userId) {
        return wrongQuestionMapper.deleteByUserId(userId);
    }

    // BaseService方法实现
    @Override
    public int add(WrongQuestion entity) {
        return wrongQuestionMapper.insert(entity);
    }

    @Override
    public int deleteById(Long id) {
        return wrongQuestionMapper.deleteById(id);
    }

    @Override
    public int update(WrongQuestion entity) {
        return wrongQuestionMapper.update(entity);
    }

    @Override
    public WrongQuestion getById(Long id) {
        return wrongQuestionMapper.selectById(id);
    }

    @Override
    public List<WrongQuestion> getAll() {
        return wrongQuestionMapper.selectAll();
    }
}